package com.hymjweb.demo.hymj.finance_manage.repayment.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hymjweb.demo.framework.result.MIniUIGridResultMap;
import com.hymjweb.demo.framework.sys.BaseService;
import com.hymjweb.demo.framework.sys.SysConstant;
import com.hymjweb.demo.framework.util.DataTypeUtil;
import com.hymjweb.demo.framework.util.DateUtil;
import com.hymjweb.demo.framework.util.DoubleUtil;
import com.hymjweb.demo.hymj.finance_manage.repayment.bean.CwRepaymentPojo;
import com.hymjweb.demo.hymj.finance_manage.repayment.detail.bean.CwRepaymentDetailPojo;
import com.hymjweb.demo.hymj.finance_manage.repayment.detail.service.CwRepaymentDetailService;
import com.hymjweb.demo.hymj.finance_manage.repayment.mapper.CwRepaymentMapper;
import com.hymjweb.demo.hymj.native_bill_manage.bean.BNativeBillPojo;
import com.hymjweb.demo.hymj.native_bill_manage.service.BNativeBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service
public class CwRepaymentService extends BaseService {

    @Autowired
    private CwRepaymentMapper cwRepaymentMapper;

    @Autowired
    private BNativeBillService bNativeBillService;

    @Autowired
    private CwRepaymentDetailService cwRepaymentDetailService;

    public Object queryRepaymentPageList(Map<String, Object> param) {
        // 设置公共查询参数,加上部门
        this.setQueryCommParam(param);
        this.pageListInit(param);
        List<Map<String, Object>> list = queryRepaymentList(param);
        MIniUIGridResultMap resultMap = this.pageToGrid(list);
        return resultMap;
    }

    public List<Map<String, Object>> queryRepaymentList(Map param) {
        List<Map<String, Object>> list = cwRepaymentMapper.queryRepaymentList(param);
        List<Map<String, Object>> humpList = DataTypeUtil.lineMapToHumpMap2(list);
        return humpList;
    }

    @Transactional(rollbackFor = {Exception.class})
    public CwRepaymentPojo getCwRepaymentPojoById(String id) {
        if(DataTypeUtil.isEmptyStr(id)){
            return null;
        }
        return cwRepaymentMapper.getCwRepaymentPojoById(id);
    }

    public Object queryReversePageList(Map param) {
        // 设置公共查询参数,加上部门
        this.setQueryCommParam(param);
        this.pageListInit(param);
        List list = queryReverseList(param);
        MIniUIGridResultMap resultMap = this.pageToGrid(list);
        return resultMap;
    }

    public List<Map<String, Object>> queryReverseList(Map param) {
        List<Map<String, Object>> list = cwRepaymentMapper.queryReverseList(param);
        return DataTypeUtil.lineMapToHumpMap2(list);
    }


    public CwRepaymentPojo convertJSONObjToJavaObj(JSONObject jsonRepaymentPojo) throws Exception {

        if (jsonRepaymentPojo == null || jsonRepaymentPojo.isEmpty()) {
            throwException("发货人还款转换失败!");
        }

        CwRepaymentPojo pojo = jsonRepaymentPojo.toJavaObject(CwRepaymentPojo.class);

        // 设置 ID
        pojo.setId(this.getSysStrId());

        // 设置初始的审核状态
        pojo.setAuditStatusId(SysConstant.XT_DIC_AUDIT_STATUS.UNAUDITED.getId());

        // 有效金额默认等于amount
        pojo.setAvailableAmount(pojo.getAmount());

        // 设置日期
        Date currentDate = DateUtil.getSysDateTime();
        String currentUserId = this.getLoginCzyId();

        pojo.setCreateTime(currentDate);
        pojo.setCreateUserId(currentUserId);
        pojo.setUpdateTime(currentDate);
        pojo.setUpdateUserId(currentUserId);

        return pojo;
    }

    @Transactional(rollbackFor = {Exception.class})
    public int addRepayment(CwRepaymentPojo cwRepaymentPojo) throws Exception {
        if (cwRepaymentPojo == null) {
            throwException("还款保存参数错误!");
        }
        return cwRepaymentMapper.insert(cwRepaymentPojo);
    }

    /**
     * 还款审核
     *
     * @param auditObj
     * @return
     */
    @Transactional(rollbackFor = {Exception.class})
    public int updateAuditStatus(JSONObject auditObj) throws Exception {

        if (auditObj == null) {
            throwException("还款审核参数错误!");
        }

        // {idList:idArray,auditStatusId:statusId}
        Long auditStatusId = DataTypeUtil.toLongObject(auditObj.get("auditStatusId"));
        JSONArray idArray = auditObj.getJSONArray("idList");
        List<Map> idList = idArray.toJavaList(Map.class);

        String czyId = this.getLoginCzyId();
        Date currentDate = this.getSysTime();

        int totalEffectRows = 0;
        for (Map map : idList) {
            String id = DataTypeUtil.toStringObject(map.get("id"));
            // 根据 id 查询到还款对象
            CwRepaymentPojo pojo = getCwRepaymentPojoById(id);
            pojo.setAuditStatusId(auditStatusId);
            pojo.setAuditUserId(czyId);
            pojo.setAuditDate(currentDate);
            pojo.setUpdateTime(currentDate);
            pojo.setUpdateUserId(czyId);

            int effectRows = update(pojo);

            totalEffectRows += effectRows;
        }

        return totalEffectRows;
    }

    /**
     * 分单位销账处理
     *
     * @param reverseObj
     * @return
     */
    @Transactional(rollbackFor = {Exception.class})
    public int addReverse(JSONObject reverseObj) throws Exception {

        if(reverseObj==null){
            throwException("分单位销账参数错误!");
        }

        // {customerId: keyDeliveryCustomerIdValue, billList: selectItems}
        // 分单位结算余额
        Map<String, Double> billBalanceMap = new HashMap<>();

        // 还款结算余额
        Map<String, Double> repaymentBalanceMap = new HashMap<>();

        String customerId = DataTypeUtil.toStringObject(reverseObj.get("customerId"));
        JSONArray billList = reverseObj.getJSONArray("billList");
        List<BNativeBillPojo> billPojos = new ArrayList<>();
        for (int i = 0; i < billList.size(); i++) {
            JSONObject jsonObject = billList.getJSONObject(i);
            BNativeBillPojo pojo = jsonObject.toJavaObject(BNativeBillPojo.class);
            pojo.setId(DataTypeUtil.toStringObject(jsonObject.get("id")));
            billPojos.add(pojo);
            billBalanceMap.put(pojo.getId(), pojo.getSettlementAmount());
        }

        /**
         * BNativeBillPojo(id=3, transportSpeciesId=72, transportWayId=81, transportScopeId=91, cityId=310000, destCityId=110000, deliveryCustomerId=386997383638089729, deliveryCustomerName=a, deliveryCustomerPhone=13811223344, deliveryCustomerAddress=fafd, deliveryCustomerContactId=387001568240664576, deliveryCustomerContactName=dsfd, deliveryCustomerContactPhone=32322, receiveCustomerName=丁明, receiveCustomerPhone=13088776655, receiveCustomerAddress=北京345号, pickUpPointId=382393992609857538, pickUpPointName=测试222, pickUpPointPhone=13899009988, pickUpPointAddress=测试222, pickUpGoodsWayId=102, signChooseId=111, deliveryCustomerSalemanId=386620592721297408, airportId=, flightDate=Mon Nov 09 00:00:00 CST 2020, flightNo=, flightName=苏B4356, airlinesId=, planTakeOffTime=16:20, goodsName=花生, goodsTypeId=51, packingWayId=122, volumeInformation={货物名称:花生,长:41,宽:45,高:67,件数:131}, totalNumber=131, actualWeight=4048.39, chargeableWeight=4048.39, weightRate=4.6, volume=16.19, volumeRate=0.0, transportCost=18622.59, declaredValue=2500.0, insuranceRate=0.3, insuranceFee=750.0, openBillDeliveryCharge=100.0, agentDeliveryCharge=80.0, tax=0.0, fuelSurcharge=0.0, collectionMoney=0.0, otherChargeList=null, otherCharges=99.0, otherChargesComment={其他费用名目:44,金额:44,备注:44} {其他费用名目:55,金额:55,备注:55}, serviceCharge=100.0, actualTransportCost=19491.59, businessCostAllocationId=11, businessCostAllocationTypeId=143, businessCostComment=按数给, printActualWeight=4048.39, printChargeableWeight=4048.39, printWeightRate=4.62, printVolume=16.19, printVolumeRate=0.0, innerOperationCharge=0.0, deliveryCustomerPaymentMethodId=151, deliveryCustomerPaymentAmount=19671.59, receiveCustomerPaymentMethodId=null, receiveCustomerPaymentAmount=0.0, totalAmount=19671.59, actualAmount=19671.59, cashierId=386620592721297408, openBillUserId=201910162259560401, openBillDate=Wed Jan 06 00:00:00 CST 2021, openBillDepartmentId=385640538562428928, rollCallDepartmentId=385640538562428928, comment=大单, billLoadStatusId=352, businessCostStatusId=322, agentDeliveryChargeStatusId=322, arrearsStatusId=321, dropStatusId=362, settlementStatusId=321, refundNumber=10, refundActualWeight=10.0, refundChargeableWeight=10.0, refundVolume=5.0, dropAmount=-100.0, settlementAmount=19571.59, shareCost=0.0, operatingCost=0.0, grossProfit=0.0, createTime=Wed Jan 06 22:13:14 CST 2021, createUserId=201910162259560401, updateTime=Sat Jan 09 15:50:38 CST 2021, updateUserId=201910162259560401)
         * BNativeBillPojo(id=4, transportSpeciesId=72, transportWayId=81, transportScopeId=91, cityId=310000, destCityId=110000, deliveryCustomerId=386997383638089729, deliveryCustomerName=a, deliveryCustomerPhone=13811223344, deliveryCustomerAddress=fafd, deliveryCustomerContactId=387001568240664576, deliveryCustomerContactName=dsfd, deliveryCustomerContactPhone=32322, receiveCustomerName=陈小明, receiveCustomerPhone=13900887766, receiveCustomerAddress=北京市234号, pickUpPointId=382393992609857538, pickUpPointName=测试222, pickUpPointPhone=13899009988, pickUpPointAddress=测试222, pickUpGoodsWayId=101, signChooseId=111, deliveryCustomerSalemanId=386620592721297408, airportId=, flightDate=Mon Nov 09 00:00:00 CST 2020, flightNo=, flightName=苏B1234, airlinesId=, planTakeOffTime=13:56, goodsName=棉花, goodsTypeId=51, packingWayId=122, volumeInformation={货物名称:棉花,长:37,宽:29,高:31,件数:55}, totalNumber=55, actualWeight=457.37, chargeableWeight=457.37, weightRate=2.6, volume=1.83, volumeRate=0.0, transportCost=1189.16, declaredValue=2500.0, insuranceRate=0.34, insuranceFee=850.0, openBillDeliveryCharge=100.0, agentDeliveryCharge=50.0, tax=10.0, fuelSurcharge=20.0, collectionMoney=0.0, otherChargeList=null, otherCharges=77.0, otherChargesComment={其他费用名目:11,金额:33,备注:33} {其他费用名目:11,金额:44,备注:44}, serviceCharge=20.0, actualTransportCost=2176.16, businessCostAllocationId=12, businessCostAllocationTypeId=141, businessCostComment=业务费用直接给了, printActualWeight=457.37, printChargeableWeight=457.37, printWeightRate=2.6, printVolume=1.83, printVolumeRate=0.0, innerOperationCharge=0.0, deliveryCustomerPaymentMethodId=151, deliveryCustomerPaymentAmount=2246.16, receiveCustomerPaymentMethodId=null, receiveCustomerPaymentAmount=0.0, totalAmount=2246.16, actualAmount=2246.16, cashierId=386620592721297408, openBillUserId=201910162259560401, openBillDate=Wed Jan 06 00:00:00 CST 2021, openBillDepartmentId=385640538562428928, rollCallDepartmentId=385640538562428928, comment=注意安全, billLoadStatusId=352, businessCostStatusId=322, agentDeliveryChargeStatusId=322, arrearsStatusId=321, dropStatusId=362, settlementStatusId=321, refundNumber=10, refundActualWeight=10.0, refundChargeableWeight=10.0, refundVolume=1.0, dropAmount=-100.0, settlementAmount=2146.16, shareCost=0.0, operatingCost=0.0, grossProfit=0.0, createTime=Wed Jan 06 22:09:58 CST 2021, createUserId=201910162259560401, updateTime=Sat Jan 09 15:50:04 CST 2021, updateUserId=201910162259560401)
         * BNativeBillPojo(id=5, transportSpeciesId=71, transportWayId=81, transportScopeId=91, cityId=310000, destCityId=110000, deliveryCustomerId=386997383638089729, deliveryCustomerName=a, deliveryCustomerPhone=13811223344, deliveryCustomerAddress=fafd, deliveryCustomerContactId=387001568240664576, deliveryCustomerContactName=dsfd, deliveryCustomerContactPhone=32322, receiveCustomerName=李相成, receiveCustomerPhone=13122003300, receiveCustomerAddress=北京223号, pickUpPointId=382393992609857538, pickUpPointName=测试222, pickUpPointPhone=13899009988, pickUpPointAddress=测试222, pickUpGoodsWayId=103, signChooseId=111, deliveryCustomerSalemanId=386620592721297408, airportId=110002, flightDate=Mon Nov 09 00:00:00 CST 2020, flightNo=389825389700046848, flightName=CAds, airlinesId=10002, planTakeOffTime=13:12, goodsName=电车, goodsTypeId=51, packingWayId=121, volumeInformation={货物名称:电车,长:23,宽:45,高:61,件数:77}, totalNumber=77, actualWeight=810.23, chargeableWeight=810.23, weightRate=4.1, volume=4.86, volumeRate=0.0, transportCost=3321.94, declaredValue=2500.0, insuranceRate=0.23, insuranceFee=575.0, openBillDeliveryCharge=100.0, agentDeliveryCharge=100.0, tax=10.0, fuelSurcharge=20.0, collectionMoney=0.0, otherChargeList=null, otherCharges=77.0, otherChargesComment={其他费用名目:33,金额:33,备注:33} {其他费用名目:44,金额:44,备注:44}, serviceCharge=30.0, actualTransportCost=4003.94, businessCostAllocationId=11, businessCostAllocationTypeId=142, businessCostComment=业务费用, printActualWeight=810.23, printChargeableWeight=817.55, printWeightRate=4.1, printVolume=4.86, printVolumeRate=0.0, innerOperationCharge=0.0, deliveryCustomerPaymentMethodId=152, deliveryCustomerPaymentAmount=4133.94, receiveCustomerPaymentMethodId=null, receiveCustomerPaymentAmount=0.0, totalAmount=4133.94, actualAmount=4133.94, cashierId=386620592721297408, openBillUserId=201910162259560401, openBillDate=Wed Jan 06 00:00:00 CST 2021, openBillDepartmentId=385640538562428928, rollCallDepartmentId=385640538562428928, comment=要说处理好, billLoadStatusId=351, businessCostStatusId=321, agentDeliveryChargeStatusId=321, arrearsStatusId=321, dropStatusId=361, settlementStatusId=321, refundNumber=0, refundActualWeight=0.0, refundChargeableWeight=0.0, refundVolume=0.0, dropAmount=0.0, settlementAmount=4233.94, shareCost=0.0, operatingCost=0.0, grossProfit=0.0, createTime=Wed Jan 06 21:56:31 CST 2021, createUserId=201910162259560401, updateTime=Thu Jan 07 14:06:08 CST 2021, updateUserId=201910162259560401)
         */
        // 根据客户 ID 检索所有所有审核通过且可用余额大于零时还款列表，注意要按日期升序，不分页 AUDIT
        List<CwRepaymentPojo> cwRepaymentPojoList = cwRepaymentMapper.queryAuditedRepaymentListByCustomerId(customerId);
        for (CwRepaymentPojo pojo : cwRepaymentPojoList) {
            repaymentBalanceMap.put(pojo.getId(), pojo.getAvailableAmount());
        }

        /**
         * CwRepaymentPojo(id=413742441849835522, customerId=386997383638089729, repaymentWayId=301, amount=20000.0, availableAmount=20000.0, registUserId=201910162259560401, registDate=Thu Jan 14 00:00:00 CST 2021, voucherFileId=413742441849835521, auditStatusId=312, auditUserId=201910162259560401, auditDate=Thu Jan 14 13:21:26 CST 2021, comment=aaaa, createTime=Thu Jan 14 11:30:47 CST 2021, createUserId=201910162259560401, updateTime=Thu Jan 14 13:21:26 CST 2021, updateUserId=201910162259560401)
         * CwRepaymentPojo(id=413742441849835525, customerId=386997383638089729, repaymentWayId=301, amount=3000.0, availableAmount=3000.0, registUserId=201910162259560401, registDate=Thu Jan 14 00:00:00 CST 2021, voucherFileId=413742441849835524, auditStatusId=312, auditUserId=201910162259560401, auditDate=Thu Jan 14 13:21:26 CST 2021, comment=aaa, createTime=Thu Jan 14 13:14:32 CST 2021, createUserId=201910162259560401, updateTime=Thu Jan 14 13:21:26 CST 2021, updateUserId=201910162259560401)
         * CwRepaymentPojo(id=413742441849835526, customerId=386997383638089729, repaymentWayId=302, amount=3000.0, availableAmount=3000.0, registUserId=201910162259560401, registDate=Thu Jan 14 00:00:00 CST 2021, voucherFileId=, auditStatusId=312, auditUserId=201910162259560401, auditDate=Thu Jan 14 13:21:26 CST 2021, comment=, createTime=Thu Jan 14 13:14:46 CST 2021, createUserId=201910162259560401, updateTime=Thu Jan 14 13:21:26 CST 2021, updateUserId=201910162259560401)
         * CwRepaymentPojo(id=413742441849835529, customerId=386997383638089729, repaymentWayId=301, amount=3000.0, availableAmount=3000.0, registUserId=201910162259560401, registDate=Thu Jan 14 00:00:00 CST 2021, voucherFileId=413742441849835528, auditStatusId=312, auditUserId=201910162259560401, auditDate=Thu Jan 14 13:21:26 CST 2021, comment=aaa, createTime=Thu Jan 14 13:19:55 CST 2021, createUserId=201910162259560401, updateTime=Thu Jan 14 13:21:26 CST 2021, updateUserId=201910162259560401)
         */

        Date currentDate = this.getSysTime();
        String czyId = this.getLoginCzyId();

        List<CwRepaymentDetailPojo> detailPojoList = new ArrayList<>();
        // billBalanceMap  repaymentBalanceMap
        String updateBillIds = "";
        for (int i = 0; i < cwRepaymentPojoList.size(); i++) {
            CwRepaymentPojo cwRepaymentPojo = cwRepaymentPojoList.get(i);
            Double repaymentBalance = repaymentBalanceMap.get(cwRepaymentPojo.getId());
            if (repaymentBalance > 0D) {
                for (int j = 0; j < billPojos.size(); j++) {
                    BNativeBillPojo billPojo = billPojos.get(j);
                    Double billBalance = billBalanceMap.get(billPojo.getId());
                    // 保存结算金额
                    Double settlementBalance = 0D;
                    if (billBalance > 0D) {
                        if (billPojo.getSettlementStatusId().longValue() == SysConstant.XT_DIC_SETTLEMENT_STATUS.UNCLEARED.getId()) {
                            if (repaymentBalance.doubleValue() >= billBalance.doubleValue()) {
                                // 分单上待结算的金额小于还款单上的结算余额
                                // 1.设置分单上的已经结算金额为0,表示该分单已经结算完成
                                billBalanceMap.put(billPojo.getId(), 0D);
                                // 2.设置分单上的结算状态与欠款状态为结清状态
                                billPojo.setSettlementStatusId(SysConstant.XT_DIC_SETTLEMENT_STATUS.CLEARED.getId());
                                billPojo.setArrearsStatusId(SysConstant.XT_DIC_SETTLEMENT_STATUS.CLEARED.getId());
                                billPojo.setUpdateTime(currentDate);
                                billPojo.setUpdateUserId(czyId);

                                // 生成更新的分单ID 字符串
                                updateBillIds += DataTypeUtil.quoteStr(billPojo.getId()) + ",";

                                // 3.设置还款单上的可用结算余额是原来分单上的可用余额减去当前分单上的金额
                                Double newRepaymentBalance = DoubleUtil.sub(repaymentBalance.doubleValue(), billBalance.doubleValue(), 2);
                                cwRepaymentPojo.setAvailableAmount(newRepaymentBalance);
                                cwRepaymentPojo.setUpdateTime(currentDate);
                                cwRepaymentPojo.setUpdateUserId(czyId);
                                repaymentBalanceMap.put(cwRepaymentPojo.getId(), newRepaymentBalance);
                                // 这个很关键，一定要设置
                                repaymentBalance = newRepaymentBalance;

                                // 4.设置结算金额
                                settlementBalance = billBalance;
                                // 5.生成 detail,并加入列表
                                detailPojoList.add(createCwRepaymentDetailPojo(billPojo.getId(), settlementBalance, cwRepaymentPojo.getId(), ""));
                            } else {
                                // repaymentBalance.doubleValue() < billBalance.doubleValue()
                                // 分单上待结算的金额大于还款单上的结算余额()
                                // 1.还款单上的可用金额要设置为0
                                cwRepaymentPojo.setAvailableAmount(0D);
                                cwRepaymentPojo.setUpdateTime(currentDate);
                                cwRepaymentPojo.setUpdateUserId(czyId);
                                repaymentBalanceMap.put(cwRepaymentPojo.getId(), 0D);

                                // 2.计算分单上的未结算余额,注意分单没有结清，所以不能设置为结算状态
                                Double newBillBalance = DoubleUtil.sub(billBalance.doubleValue(), repaymentBalance.doubleValue(), 2);
                                billBalanceMap.put(billPojo.getId(), newBillBalance);

                                // 3.设置结算金额
                                settlementBalance = repaymentBalance;
                                // 4.生成 detail,并加入列表
                                detailPojoList.add(createCwRepaymentDetailPojo(billPojo.getId(), settlementBalance, cwRepaymentPojo.getId(), ""));
                                // 6.当前还款单的金额已经变为0了，所以分单再循环没有意义，直接 break 退出内循环,启用下一条还款余额
                                break;
                            }
                        }
                    }


                }
            }
        }

        // 开始遍历做扣款操作，同时生成cw_repayment_detail 表对象，并做好记入数据库，需要注意一分单费用跨多次还款的问题，这个地方的逻辑要好好设计
        // 调用相应服务进行更新，通过循环操作完成
        // 1.更新分单状态，注意为了防止没有读取到的值，更新为 null ,则就直接更新相应字段就好
        if (updateBillIds.length() > 0) {
            updateBillIds = updateBillIds.substring(0, updateBillIds.length() - 1);
            int billEffectRows = bNativeBillService.updateStatusId("settlement_status_id", SysConstant.XT_DIC_SETTLEMENT_STATUS.CLEARED.getId(), updateBillIds, this.getSysTime(), this.getLoginCzyId());
            billEffectRows = bNativeBillService.updateStatusId("arrears_status_id", SysConstant.XT_DIC_SETTLEMENT_STATUS.CLEARED.getId(), updateBillIds, this.getSysTime(), this.getLoginCzyId());
        }

        // 2.更新还款的可用金额,这个由于是查询到的完整对象，可以直接更新
        int cwRepaymentEffectRows = 0;
        for (CwRepaymentPojo pojo : cwRepaymentPojoList) {
            cwRepaymentEffectRows += update(pojo);
        }

        // 3.批量插入数据
        int insertEffectRows = cwRepaymentDetailService.batchInsert(detailPojoList);

        return insertEffectRows;
    }


    /**
     * id
     * native_bill_id
     * settlement_amount
     * repayment_id
     * comment
     * create_time
     * create_user_id
     * update_time
     * update_user_id
     */
    public CwRepaymentDetailPojo createCwRepaymentDetailPojo(String billId, Double settlementAmount, String repaymentId, String comment) {
        Date currentDate = this.getSysTime();
        String czyId = this.getLoginCzyId();
        CwRepaymentDetailPojo detailPojo = new CwRepaymentDetailPojo();
        detailPojo.setId(this.getSysStrId());
        detailPojo.setNativeBillId(billId);
        detailPojo.setSettlementAmount(settlementAmount);
        detailPojo.setRepaymentId(repaymentId);
        detailPojo.setComment(comment);
        detailPojo.setCreateTime(currentDate);
        detailPojo.setCreateUserId(czyId);
        detailPojo.setUpdateTime(currentDate);
        detailPojo.setUpdateUserId(czyId);
        return detailPojo;
    }

    @Transactional(rollbackFor = {Exception.class})
    public int update(CwRepaymentPojo pojo) throws Exception {
        if(pojo==null){
            throwException("还款更新参数错误!");
        }
        return cwRepaymentMapper.update(pojo);
    }

}
